var ifm = require('../models/ifm.js');
var cfm = require('../models/cfm.js');
var user;
var ifmIndex = require('../models/ifmIndex.js');
var cfmIndex = require('../models/cfmIndex.js');
//var generate = require('../models/generate.js');
var regex = /^_/;
var ObjectID = require("mongodb").ObjectID;

exports.setUser = function(req_user){
    user = req_user;
    console.log("set User:"+user);
}
exports.test = function(res,callback){
    //ccd_index
    cfm_Demo[0].user = user;
    var filter = {
        cfm_creator: cfm_Demo[0].user
        ,name: cfm_Demo[0].name
        ,description: cfm_Demo[0].description
    }
    cfmIndex.remove([null,null],function(){
        cfmIndex.create([filter,null],function(err,doc){
            //if(err) return res.redirect("/reset");
            var ccdDoc = doc[0];
            var filter={};
            filter["user"]=user;
            ifmIndex.remove(null,function(err,doc){
                ifmIndex.create(filter,function(err,doc){
                    return callback();
                })
            });
        });
    })
}



var cfm_Demo =[
    {
        user : user,
        name: "Financial Threaten",
        description : "Demo of a financial threaten model"
    },
    {
        Entity:1
        ,Property:1
        ,Impact:1
        ,Threat:1
        ,CounterMeasure:1
    }
];